clear
clear matrix
program drop _all
capture log close
cd C:\Users\dpage\Desktop\Clash_Project\

use Latinobarometro_2015_Eng.dta, clear 

set more off

egen country = group(idenpa)

tab idenpa
tab country 

gen SCone = 0
replace SCone = 1 if country==1 | country==4 | country==17 

recode S18 -7=. -6=0 -5=. -4=. -3=. -2=. -1=. 0=., gen(EdYears)   
recode P27ST -1=. -2=. -3=. -4=. -5=. -6=. -7=. -8=., gen(LRIdeology) 
gen Age = S13

recode P69ST_C -1=. -2=. -3=., gen(opposegay)
recode P25ST -2=. -1=. 2=0, gen(votemakesadifference)

proportion votemakesadifference if opposegay<3 
proportion votemakesadifference if opposegay>2

mean Age if opposegay<3 
mean Age if opposegay>2

mean EdYears if opposegay<3 
mean EdYears if opposegay>2

mean LRIdeology if opposegay<3 
mean LRIdeology if opposegay>2


gen SConeGay = SCone*opposegay 

*Southern Cone 
logit votemakesadifference opposegay EdYears LRIdeology if SCone==1
*Non-Southern Cone
logit votemakesadifference opposegay EdYears LRIdeology if SCone==0

*Interaction Model  
melogit votemakesadifference SCone opposegay SConeGay Age EdYears LRIdeology [pw=wt] ||idenpa: 
outreg2 using ISAvotemakesadifference, word replace 

set more off 
			 
		sum LRIdeology
			gen LR_mean = r(mean)  
		sum Age 
			gen Age_mean = r(mean)
		sum EdYears
			gen Ed_mean = r(mean)
		
		keep if _n==1 
		keep LR_mean Age_mean Ed_mean 
		 
		matrix def b = e(b)
		matrix def V = e(V)
		mat list b
		mat list V
		
		set more off
		save FirstDifferencesIVs.dta, replace
		
		*program drop firstdiff2
	program define firstdiff2
	use FirstDifferencesIVs.dta, clear
	
	drawnorm b1-b8, means(b) cov(V)
		

	*Southern Cone
		#delimit ;
		gen pParticipation15d = b1*1 + b2*4 + b3*1*4 +
		b4*Age_mean + b5*Ed_mean + b6*LR_mean + b7 
		;
		#delimit cr

		#delimit ;
		gen pParticipation15nd = b1*1 + b2*1 + b3*1*1 +
		b4*Age_mean + b5*Ed_mean + b6*LR_mean + b7 
		;
		#delimit cr
	
	*Non-Southern Cone 
		#delimit ;
		gen pParticipationEd = b1*0 + b2*4 + b3*4*0 +
		b4*Age_mean + b5*Ed_mean + b6*LR_mean + b7 
		;
		#delimit cr

		#delimit ;
		gen pParticipationEnd = b1*0 + b2*1 + b3*1*0 +
		b4*Age_mean + b5*Ed_mean + b6*LR_mean + b7 
		;
		#delimit cr
		
		gen Participation15d = exp(pParticipation15d)/(1+exp(pParticipation15d))
		gen Participation15nd = exp(pParticipation15nd)/(1+exp(pParticipation15nd))
		gen ParticipationEd = exp(pParticipationEd)/(1+exp(pParticipationEd))
		gen ParticipationEnd = exp(pParticipationEnd)/(1+exp(pParticipationEnd))
		
		gen DiffEast = ParticipationEd - ParticipationEnd
		gen DiffWest = Participation15d - Participation15nd

		append using FirstDiffs2.dta
			save FirstDiffs2.dta, replace
			
			end
							
			clear
			save FirstDiffs2.dta, replace emptyok
	
			set more off
			
			simulate, reps(1500):  firstdiff2

			use FirstDiffs2.dta, clear

			
						set more off			
#delimit ; 
collapse (mean) 
Participation15d Participation15nd ParticipationEd ParticipationEnd DiffEast DiffWest
 (sd)
 Participation15d_sd=Participation15d Participation15nd_sd=Participation15nd 
 ParticipationEd_sd=ParticipationEd ParticipationEnd_sd=ParticipationEnd
 DiffEast_sd=DiffEast  DiffWest_sd=DiffWest
 ;
#delimit cr 	


gen Participation15d_hi = Participation15d + 1.96*Participation15d_sd
gen Participation15d_lo = Participation15d - 1.96*Participation15d_sd

gen Participation15nd_hi = Participation15nd + 1.96*Participation15nd_sd
gen Participation15nd_lo = Participation15nd - 1.96*Participation15nd_sd

gen ParticipationEd_hi = ParticipationEd + 1.96*ParticipationEd_sd
gen ParticipationEd_lo = ParticipationEd - 1.96*ParticipationEd_sd

gen ParticipationEnd_hi = ParticipationEnd + 1.96*ParticipationEnd_sd
gen ParticipationEnd_lo = ParticipationEnd - 1.96*ParticipationEnd_sd 

gen DiffEast_hi = DiffEast + 1.96*DiffEast_sd
gen DiffEast_lo = DiffEast - 1.96*DiffEast_sd

gen DiffWest_hi = DiffWest + 1.96*DiffWest_sd
gen DiffWest_lo = DiffWest - 1.96*DiffWest_sd

browse

gen axis_LFS1_B = 1
gen axis_LFS2_B = 2
gen axis_LFS3_B = 3
gen axis_LFS4_B = 4

lab def afmtlf2 1 "Disagree" 2 "Agree" 3 "Disagree" 4 "Agree" 
label val axis_LFS1_B afmtlf2 

#delimit ;
twoway (bar Participation15d axis_LFS1_B, 
			color(black) barwidth(.5))
		(rcap Participation15d_lo Participation15d_hi axis_LFS1_B,
			lcolor(gs10))
		(bar Participation15nd axis_LFS2_B, 
			color(black) barwidth(.5))
		(rcap Participation15nd_lo Participation15nd_hi axis_LFS2_B,
			lcolor(gs10))
		(bar ParticipationEd axis_LFS3_B , 
			color(gs10) barwidth(.5))
		(rcap ParticipationEd_lo ParticipationEd_hi axis_LFS3_B,
			lcolor(black))
		(bar ParticipationEnd axis_LFS4_B, 
			color(gs10) barwidth(.5))
		(rcap ParticipationEnd_lo ParticipationEnd_hi axis_LFS4_B,
			lcolor(black)),
legend(off)
ylabel(.2(.2)1)
ytitle("Pr(Vote Makes a Difference)", size(medlarge))
title("Those who disagree and agree with same-sex marriage", size(med))
xlabel(#3,valuelabel angle(horizontal))
name(GPH1, replace)
scheme(s1mono);
#delimit cr	


	    #delimit ;
		twoway (bar DiffWest axis_LFS1_B, color(black)) (rcap DiffWest_hi DiffWest_lo axis_LFS1_B, color(gs10)) 
		(bar DiffEast axis_LFS2_B, color(gs10)) (rcap DiffEast_hi DiffEast_lo axis_LFS2_B, color(black)), 
		scheme(s1mono) ylabel(.2(.1) -.2) ytitle("Diff. in Pr(Makes A Difference)", size(medlarge))
		yline(0)
		title("Difference in Pr(Makes a difference) between" "Those who disagree and agree with same-sex marriage", size(med))
		xlabel( 1 "Southern Cone" 2 "Not in the Southern Cone", noticks) 
		name(GPH2, replace)  
		 legend(off)
		;
		#delimit cr

#delimit ;	
	graph combine GPH1 GPH2, rows(2) ysize(9) xsize(5) title("A1Figure1: Probability to believe one's vote makes a difference by" 
	"agreement with same-sex marriage and whether one lives" "in the Southern Cone with 95 percent confidence intervals.", size(medsmall))
note("My vote makes a difference(1), My vote doesn't make a difference(0)." "Data source: Latinobarometer 2015", size(medsmall)) scheme(s1mono)
;
#delimit cr

